package com.foreveross.fetl.core.domain.freight.repository.impl;

import java.util.ArrayList;
import java.util.List;



import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.foreveross.fetl.common.jpa.EntityHibernateRepository;
import com.foreveross.fetl.core.domain.freight.FetlDataEntity;
import com.foreveross.fetl.core.domain.freight.repository.IFetlDataRepository;

@Repository("fetlDataRepository")
public class FetlDataRepositoryImpl extends EntityHibernateRepository implements
		IFetlDataRepository {

	@Override
	public List<FetlDataEntity> findByCondition(String channel,String fromCity, String toCity) {
		List<Object> conditionVals = new ArrayList<Object>();
		StringBuilder jpql =new StringBuilder("select fde from FetlDataEntity fde where 1=1");
		if(channel!=null && !"".equals(channel)){
			jpql.append(" and fde.attachHbaseKey = ?");
			conditionVals.add(channel);
		}
		if(fromCity!=null && !"".equals(fromCity)){
			jpql.append(" and fde.fromCity = ?");
			conditionVals.add(fromCity);
		}
		if(toCity!=null && !"".equals(fromCity)){
			jpql.append(" and fde.toCity = ?");
			conditionVals.add(toCity);
		}
		List<FetlDataEntity> list =super.queryResult(jpql.toString(), conditionVals.toArray());
		return list;
	}

	@Override
	public Query createQuery(String hql,Object[] params) {
		return super.createQuery(hql, params);
	}
}
